package com.jigu.admin.controller;

import com.jigu.admin.model.console.Menu;
import com.jigu.admin.service.MenuService;
import com.jigu.core.exception.NotFoundException;
import com.jigu.core.utils.ResponseMessage;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by toretto on 2017/6/22.
 */

@RestController
@RequestMapping(value = "/console/menu")
public class MenuController {

    @Autowired private MenuService menuService;

    /**
     * 获取所有子菜单栏
     * @return
     */
    @GetMapping(value = "index")
    public ResponseMessage index(){

        ArrayList<Menu> menuList = new ArrayList<>();
        List<Menu> lists = menuService.getChildMenuList(menuList,"0");

        if (!lists.isEmpty()){
            return ResponseMessage.created(lists);
        }

        throw new NotFoundException("服务器出错");
    }

    /**
     * 获取所有菜单
     * @return
     */
    @GetMapping(value = "list")
    public ResponseMessage menuList(){

        List<Menu> menuList = menuService.getAllMenus();
        if (!menuList.isEmpty()){
            return ResponseMessage.created(menuList);
        }
        throw new NotFoundException("服务器出错");
    }

}
